﻿using HtmlParserLib;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;

namespace WpfMonitor
{
    class DataTemplateSelectorBase : DataTemplateSelector
    {
        protected MainWindow GetMainWindow(DependencyObject inContainer)
        {
            DependencyObject c = inContainer;
            while (true)
            {
                DependencyObject p = VisualTreeHelper.GetParent(c);

                if (c is MainWindow)
                {
                    return c as MainWindow;
                }
                else
                {
                    c = p;
                }
            }
        }

        public override DataTemplate SelectTemplate(object inItem, DependencyObject inContainer)
        {
            var item = inItem as ReportEventArgs;

            if (item != null)
            {
                MainWindow w = GetMainWindow(inContainer);

                var template = (DataTemplate)w.FindResource("ReportType" + item.ReportType.ToString() + "Image");
                return template;
                
            }
            return null;
        }
    }
}
